﻿@using Citi.GocAttributes.Domain
@model IEnumerable<Citi.GocAttributes.WebUI.Models.RuleConditionModel>
@Html.Partial("~/Views/PartialView/AutoCompleteLevel.cshtml",
        new Citi.GocAttributes.WebUI.Models.AutoCompleteLevelModel
        {
            HiddenIdInput = "ConditionValueIdFunction",
            AutoCompleteInput = "ConditionValueFunction",
            LevelInput = "ConditionLevelFunction",
            ControllerName = "Function"
        })
@Html.Partial("~/Views/PartialView/AutoCompleteLevel.cshtml",
        new Citi.GocAttributes.WebUI.Models.AutoCompleteLevelModel
        {
            HiddenIdInput = "ConditionValueIdManagedSegment",
            AutoCompleteInput = "ConditionValueManagedSegment",
            LevelInput = "ConditionLevelManagedSegment",
            ControllerName = "ManagedSegment"
        })
<table cellpadding="2">
    @foreach (var ruleType in Enum.GetValues(typeof(DatabaseEnums.RuleType)).Cast<DatabaseEnums.RuleType>())
    {
        var condition = Model != null ? Model.FirstOrDefault(x => x.Type == ruleType) : null;

        var value = condition == null
                        ? string.Empty
                        : ruleType == DatabaseEnums.RuleType.Function
                              ? string.Concat(condition.Function.Code, " - ", condition.Function.Description)
                              : ruleType == DatabaseEnums.RuleType.ManagedSegment
                                    ? string.Concat(condition.ManagedSegment.Code, " - ", condition.ManagedSegment.Description)
                                    : condition.Value;
              
        
        <tr>
            <td>
                <b>@ruleType.GetDescription()</b>
            </td>
            <td>
                @if (ruleType == DatabaseEnums.RuleType.ManagedSegment || ruleType == DatabaseEnums.RuleType.Function)
                {
                    var treeLevel = condition == null ? string.Empty : ruleType == DatabaseEnums.RuleType.ManagedSegment
                            ? condition.ManagedSegment.TreeLevel.ToString()
                            : condition.Function.TreeLevel.ToString();
                    <text>Level:
                    @Html.TextBox(string.Concat("ConditionLevel", ruleType), treeLevel,
                        new { style = "width:30px", maxlength = 2, @class = "integer" })</text>
                    @Html.Hidden(string.Concat("ConditionValueId", ruleType),
                        condition == null
                            ? string.Empty
                            : ruleType == DatabaseEnums.RuleType.ManagedSegment
                                ? condition.ManagedSegmentId.ToString()
                                : condition.FunctionId.ToString())
                }
            </td>
            <td>
                Value:
                @Html.TextBox(string.Concat("ConditionValue", ruleType), value, new { style = "width:350px" })
            </td>
        </tr>
    }
</table>
